package org.openkoala.koala.wizard.wizardpage;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
import org.openkoala.koala.widget.Project;

/**
 * 项目名称录入、项目路径选择、工作集选择界面
 * @author xmfang
 *
 */
public class NameLocationWizardPage extends WizardNewProjectCreationPage {

    private ISelection selection;
	private IWorkbench workbench;
	private Project project;
	
	public NameLocationWizardPage(IWorkbench workbench, ISelection selection, Project project) {
		super("New Simple Project");
		this.workbench = workbench;
		this.selection = selection;
		this.project = project;
	}

	@Override
	public void createControl(Composite parent) {
		super.createControl(parent);

		IWorkingSet[] workingSets = workbench.getWorkingSetManager().getWorkingSets();
		String[] workingSetStrings = new String[workingSets.length];
		for (int i = 0; i < workingSets.length; i++ ) {
			workingSetStrings[i] = workingSets[i].getId();
		}

		createWorkingSetGroup((Composite) getControl(),
				(IStructuredSelection) selection,
				workingSetStrings);
		Dialog.applyDialogFont(getControl());
	}

//	@Override
//	protected boolean validatePage() {
//		if (getProjectName().contains("-")) {
//			setErrorMessage("- is an invalid character in resource name '" + getProjectName() + "'.");
//			return false;
//		}
//		return super.validatePage();
//	}
	
	@Override
    public IWizardPage getNextPage() {
		MavenInfoWizardPage mavenInfoWizardPage = (MavenInfoWizardPage) getWizard().getPage("MavenInfoWizardPage");
		mavenInfoWizardPage.refreshArtifactId(getProjectName());
		
		project.setAppName(getProjectName());
		project.setPath(getLocationPath().toString());
		return super.getNextPage();
    }
	
}
